package com.cloud.shopping.job.dynamic;

import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author John.zhang
 * @version Id: DynamicConfig, v 1.0 2021/1/8 13:49 ZhiYong Exp $
 */

@Configuration
public class DynamicConfig {
    @Value("${dynamic_zk}")
    private String dynamicZk;

    @Value("${dynamic_namespace}")
    private String dynamicNamespace;

    /**
     * 指定当前注册地址信息
     */
    @Bean
    public ZookeeperConfiguration zookeeperConfiguration() {
        return new ZookeeperConfiguration(dynamicZk,dynamicNamespace);
    }

    /**
     * 向Zookeeper服务注册
     */
    @Bean(initMethod = "init")
    public ZookeeperRegistryCenter zookeeperRegistryCenter(ZookeeperConfiguration zookeeperConfiguration){
        return new ZookeeperRegistryCenter(zookeeperConfiguration);
    }
}
